<template>
  <div class="jioninfo-dialog">
    <el-dialog
      v-model="dialogVisible"
      @open="onOpen"
      @close="onClose"
      title="成果详情"
    >
      <el-row>
        <el-col :span="24" class="list-title">任务清单</el-col>
      </el-row>
      <el-table :data="checkList">
        <el-table-column
          label="任务描述"
          align="center"
          prop="content"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="成果附件"
          align="center"
          prop="infomation"
          :show-overflow-tooltip="true"
        >
          <template #default="scope">
            <span>{{
              scope.row.isSubmit ? scope.row.information.name : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="截止时间"
          align="center"
          prop="endTime"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="上传时间"
          align="center"
          prop="submitTime"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <template v-if="scope.row.isSubmit">
              <el-button
                link
                type="primary"
                icon="Download"
                @click="download(scope.row.information)"
                >下载</el-button
              >
              <el-button
                link
                type="primary"
                icon="Reading"
                @click="preview(scope.row.information)"
                >预览</el-button
              >
              <el-button
                link
                type="primary"
                icon="Delete"
                @click="handleDelete(scope.row.information.id)"
                >删除</el-button
              >
            </template>
          </template>
        </el-table-column>
      </el-table>
      <PreviewDialog
        v-model="dialogPreviewVisible"
        :infor="currentInfor"
      ></PreviewDialog>
      <template #footer>
        <el-button @click="close">取消</el-button>
        <!-- <el-button type="primary" @click="handelConfirm">确定</el-button> -->
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import useActivityStore from "@/store/modules/activity";
import { getToken } from "@/utils/auth";
import { getStageInfo } from "@/api/pms/project";
import PreviewDialog from "./previewDialog.vue";

const headers = ref({
  Authorization: "Bearer " + getToken(),
});
const baseURL = import.meta.env.VITE_APP_BASE_API;
const { proxy } = getCurrentInstance();
const props = defineProps({
  currentStage: { type: Object, default: {} },
  userId: { type: String, default: "" },
});
const formRef = ref();
const ruleFormRef = ref();
const checkList = ref([]);
const loading = ref(false);
const proTypeOptions = ref([]);
const sponsor = ref(""); //主办方
const currentInfor = ref({});
const dialogPreviewVisible = ref(false);
// 上传请求路径
const imgUrlAction = ref(import.meta.env.VITE_APP_BASEURL + "/common/upload");
// 上传文件列表
// 弹窗设置
const dialogVisible = defineModel();
// 弹窗确认回调
const emit = defineEmits(["confirm"]);
/**
 * @name: 弹窗打开后执行
 * @description: 弹窗打开后执行方法
 * @return {*}
 */
async function onOpen() {
  getList();
}
//修改时初始化
function getList() {
  loading.value = true;
  let params = {
    stageId: props.currentStage.id,
    userId: props.userId,
  };
  getStageInfo(params).then((response) => {
    checkList.value = response.data;
    loading.value = false;
  });
}
/** 下载文件 */
function download(item) {
  proxy.download(
    "/common/download",
    {
      fileName: item.url.replace("/profile/upload", ""),
      delete: false,
    },
    item.name
  );
}
/**
 * @name: 弹窗关闭时执行
 * @description: 弹窗关闭方法，重置表单
 * @return {*}
 */
function onClose() {}
/**
 * @name: 弹窗取消
 * @description: 弹窗取消方法
 * @return {*}
 */
function close() {
  dialogVisible.value = false;
}
//打开在线预览弹窗
function preview(item) {
  currentInfor.value = item;
  dialogPreviewVisible.value = true;
}
/**
 * @name: 弹窗表单提交
 * @description: 弹窗表单提交方法
 * @return {*}
 */
</script>
<style lang="scss">
.el-upload__tip {
  line-height: 1.2;
}
.file-tip {
  padding-left: 100px;
  color: red;
  margin-bottom: 5px;
  margin-top: 12px;
  display: inline-block;
}
.jioninfo-dialog {
  .el-dialog {
    .el-dialog__body {
      height: 70vh;
      overflow-y: auto;
      .el-row {
        padding: 10px 0;
      }
    }
  }
}
</style>
